//////////

#include <string.h>
#include "../basic/operator.h"

/*
Cell* make_syntax(Scheme *sc, const char *name) {
	Cell* symbol = make_symbol(sc, name);
	symbol->_type = SYNTAX_TYPE;
	return symbol;
}
*/

Cell* make_syntax(Scheme *sc, const char *name, OperatorFunc f) {
    Cell* x = make_cell(sc, G_NIL, G_NIL);
    // (x)->_flag = T_ATOM;
    (x)->_type = SYNTAX_TYPE;
    (x)->_name = name;
    (x)->_op = f;
    return (x);
}

Cell* syntax_op(Scheme *sc, Cell* syntax) {
    if (syntax->_name == NULL) {
        return G_NIL;
    }

    Cell* frame = first(sc->globalEnv);
    int location = hash_fn(syntax->_name, frame->_longValue);
    Cell* item = get_vector_item(frame, location);
    Cell* slot = NULL;
    Cell* op = NULL;
    for (; item != G_NIL; item = cdr(item)) {
        slot = car(item);
        if (strcmp(car(slot)->_type, SYNTAX_TYPE) == 0 && strcmp(car(slot)->_name, syntax->_name) == 0) {
            op = cdr(slot);
            break;
        }
    }
    if (op != NULL && strcmp(op->_type, SYNTAX_TYPE) == 0) {
        return op;
    }
    return G_NIL;
}

/*
Cell* syntax2op(Cell* p) {
	const char *s = car(p)->_string;

	if (strcmp(s, "if") == 0) {////
		return cell_op_if0;
	} else if (strcmp(s, "or") == 0) {////
		return cell_op_or0;
	} else if (strcmp(s, "and") == 0) {////
		return cell_op_and0;
	} else if (strcmp(s, "let") == 0) {////
		return cell_op_let0;
	} else if (strcmp(s, "case") == 0) {////
		return cell_op_case0;
	} else if (strcmp(s, "cond") == 0) {////
		return cell_op_cond0;
	} else if (strcmp(s, "let*") == 0) {////
		return cell_op_letstar0;
	} else if (strcmp(s, "set!") == 0) {////
		return cell_op_set0;
	} else if (strcmp(s, "begin") == 0) {////
		return cell_op_begin;
	} else if (strcmp(s, "delay") == 0) {////
		return cell_op_delay;
	} else if (strcmp(s, "quote") == 0) {////
		return cell_op_quote;
	} else if (strcmp(s, "lambda") == 0) {////
		return cell_op_lambda;
	} else if (strcmp(s, "define") == 0) {////
		return cell_op_def0;
	} else if (strcmp(s, "letrec") == 0) {////
		return cell_op_let0rec;
	} else if (strcmp(s, "cons-stream") == 0) {////
		return cell_op_c0stream;
	}

	return &g_nil;
}
*/
